/*
 * CategoryTreeAddressItem.java
 * business
 *
 * Created by SunDing on 2016/9/9.
 *
 * Copyright (c) 2016年 yidiandao. All rights reserved.
 */

package com.yidiandao.business.ui.widget.listview.displaylistitem;

import android.app.Activity;
import android.content.Context;
import android.support.v4.util.ArrayMap;

import com.yidiandao.business.R;
import com.yidiandao.business.data.bean.Tag;
import com.yidiandao.business.data.response.CategoryResponse;
import com.yidiandao.business.ui.searchabout.categorysearchgoods.CategorySearchGoodsActivity;
import com.yidiandao.business.ui.widget.listview.DisplayListItem;
import com.yidiandao.business.ui.widget.listview.viewholder.CategoryTreeAddressHolder;
import com.yidiandao.business.ui.widget.view.TagFlowLayout;
import com.yidiandao.business.ui.widget.view.TagView;
import com.yidiandao.business.utils.UmengUtils;

import java.util.ArrayList;
import java.util.List;

/** 分类 产地 */
public class CategoryTreeAddressItem
        extends DisplayListItem<
        CategoryTreeAddressHolder, List<CategoryResponse.DataBean.CatListBean.Cat>> {

    public CategoryTreeAddressItem(List<CategoryResponse.DataBean.CatListBean.Cat> list) {
        super(list);
    }

    @Override
    public void onShow(final Context context, CategoryTreeAddressHolder holder) {
        //存储产地名
        List<Tag> tags = new ArrayList<>();
        //存储产地名与id的键值对
        final ArrayMap<String, String> map = new ArrayMap<>();
        //遍历集合
        for (CategoryResponse.DataBean.CatListBean.Cat cat : data) {
            tags.add(new Tag(cat.getCat_name()));
            map.put(cat.getCat_name(), cat.getCat_id());
        }

        holder.mTagLayout.setTagState(TagView.CATEGORY);
        holder.mTagLayout.setTagsData(tags);

        holder.mTagLayout.setTagListener(
                new TagFlowLayout.TagListener() {
                    @Override
                    public void onTagClick(TagView tagView) {
                        String tagDataName = tagView.getTagDataName();
                        String id = map.get(tagDataName);
                        UmengUtils.onEvent(context, R.string.umeng_category_address);
                        CategorySearchGoodsActivity.actionStart(
                                (Activity) context, id, tagDataName);
                    }

                    @Override
                    public void onTextChanged(String text) {
                    }
                });
    }

    @Override
    public String getDisplayItemTag() {
        return CategoryTreeAddressItem.class.getSimpleName();
    }

    @Override
    public Class<CategoryTreeAddressHolder> getViewHolderClazz() {
        return CategoryTreeAddressHolder.class;
    }
}
